home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 440_01 / examples / ex_3.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-16  |  4.1 KB  |  71 lines

  1. #include <stdlib.h>
  2. #include "colors.h"
  3. #include "!bestlib.h"
  4.  
  5.    /*** NOTE  the names and structure of the routines used in these examples
  6.               have changed in The Best Library 2.00; the updated examples will
  7.               be released soon                                            ***/
  8.  
  9.    /*** NOTE  even though this program only uses the "keyp" and "prdata"
  10.               structures, the other two are necessary for the assembler
  11.               routines in the !BESTLIB.LIB library to function properly.  C
  12.               would also produce a "linker warning" if you have enabled that
  13.               warning                                                     ***/
  14. filldata fidata;                       /* create a "filldata" structure     */
  15. printdata prdata = { WHITE, BLUE, -1, 1, 1, "Press any key to exit" };
  16.     /* see "printdata" under GLOBAL VARIABLES for explanation of the values */
  17. mousedata msdata;                      /* create a "mousedata" structure    */
  18. asciiscan keyp;                        /* create an "asciiscan" structure   */
  19.  
  20. void main(void)
  21. {
  22.    int oldmode, deltax = 1, deltay = 1, mouse, delaytime, z;
  23.    char input[80];          /* enough space for a 79-letter string and NULL */
  24.  
  25.    oldmode = readvideomode();          /* save the current video mode       */
  26.    if (oldmode == 3 || oldmode == 7 || oldmode == 21) {
  27.                                        /* if the old mode was a text mode.. */
  28.       textmem(3);                      /* store text video memory           */
  29.       cursor(3, 1);                    /* hide and store cursor position    */
  30.    }
  31.    textm(1);                          /* change to 80x25x16 color text mode */
  32.    clear(LIGHTGRAY, BLACK);            /* clear the screen and set colors   */
  33.    printsatxy("What text would you like to be animated? (79 letters maximum)",
  34.                1, 10);
  35.    z = readstring(input, 79, 0, 11);   /* ask user for the text to animate  */
  36.    if (z == -1) prdata.string2print = "Demonstration";
  37.    else prdata.string2print = input;   /* set up the text for printing      */
  38.    printsatxy("Enter movement delay in milliseconds (1-1000): [30]", 1, 13);
  39.    z = readnumber(1000, 1, 53, 13, &delaytime);  /* ask user for delay time */
  40.    if (z == FALSE) delaytime = 30;     /* if <ENTER> or <ESC>, use default  */
  41.    clear(WHITE, BLUE);                 /* clear the screen and set colors   */
  42.    mouse = initms();                   /* initialize mouse if installed     */
  43.    msec(1);                            /* initialize CPU-independent delay  */
  44.  
  45.    if (mouse == TRUE)                  /* if the mouse was initialized..    */
  46.       xyminmaxms(9, 4, 70, 20);        /* restrict its movement (for show)  */
  47.    while (!keyhit()) {                 /* loop until a key is pressed       */
  48.       print();                         /* print user-inputted text          */
  49.       if (mouse == TRUE) printsatxy("The mouse is just for show", 27, 0);
  50.       printsatxy("Press any key to exit", 29, 24);
  51.       if (mouse == TRUE) showms();     /* restore mouse cursor onto screen  */
  52.       msec(delaytime);                 /* wait 10 milliseconds              */
  53.       if (mouse == TRUE) hidems();     /* hide mouse before a screen update */
  54.       if (prdata.x >= 80 - stringlenpr() || prdata.x <= 0)
  55.                                        /* if the x-coordinate is at an edge */
  56.          deltax = -deltax;             /* reverse the x-increment (negate)  */
  57.       if (prdata.y >= 24 || prdata.y <= 0) /* if y-coordinate is at an edge */
  58.          deltay = -deltay;             /* reverse the y-increment (negate)  */
  59.       stringerasepr();                 /* erase user inputted text          */
  60.       prdata.x += deltax,
  61.       prdata.y += deltay;              /* increment the x and y coordinates */
  62.    }
  63.  
  64.    changevideomode(oldmode);           /* restore the original video mode   */
  65.    if (oldmode == 3 || oldmode == 7 || oldmode == 21) {
  66.                                        /* if the old mode was a text mode.. */
  67.       textmem(1);                      /* restore text video memory         */
  68.       cursor(1, 1);                    /* show and restore cursor position  */
  69.    }
  70. }
  71.